package demo.test.xxx;

import com.just_bean.JustBeanApplication;
import com.just_bean.core.bean.BaseBean;
import com.just_bean.core.handler.AnnoHandler;
import demo.test.anno.Component;
import demo.test.anno.DI;
import demo.test.anno.LogTs;
import demo.test.anno.Time;
import demo.test.bean.ComponentBean;
import demo.test.bean.TimeBean;
import demo.test.handler.DIHandler;
import demo.test.handler.LogTsHandler;
import demo.test.xxx.entity.BaseTime;
import demo.test.xxx.entity.WDJ;

import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;

public class Demo {
    public static void main(String[] args) throws Exception {
        DIHandler diHandler = new DIHandler();
        // 注册AnnoHandler
        Map<Class<? extends Annotation>, AnnoHandler> handlerMap = new HashMap<>();
        handlerMap.put(LogTs.class, new LogTsHandler());
        handlerMap.put(DI.class, diHandler);

        // 注册BaseBean
        Map<Class<? extends Annotation>, Class<? extends BaseBean>> beanClzMap = new HashMap<>();
        beanClzMap.put(Time.class, TimeBean.class);
        beanClzMap.put(Component.class, ComponentBean.class);

        JustBeanApplication application = JustBeanApplication.emptyApp(Demo.class, handlerMap, beanClzMap);

        diHandler.setJustBeanApplication(application);

        // 使用框架
        application.get(WDJ.class).lala("haha");

        new Thread(() -> {
            while (true) {
                try {
                    Thread.sleep(5 * 1000);
                    System.out.println(application.get(BaseTime.class).hashCode());
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }).start();
        /** 输出：
         * 102816857
         * 102816857
         * 102816857
         * 1552472867
         * 1552472867
         * 1552472867
         * 1254111512
         * 1254111512
         */
    }
}
